﻿using MoveView.MyMath;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MoveView.MyMath
{
    public class CameraCalc
    {
        public CameraCalc(double radiusmax)
        {
            this.radiusmax = radiusmax;
            this.r = radiusmax;
            calculateCartesianCoordinates();
        }

        #region Spherical coordinate system
        XYZ sc; //spherical coordinates        
        private double radiusmax = 20;
        private const double radiusmin = 0.5;
        /// <summary>
        /// Azimutal angle of spherical coordinate system
        /// </summary>
        public double a 
        {
            get { return sc.x; }
            set { sc.x = value % (2 *Math.PI);
            calculateCartesianCoordinates();
            }
        }
        /// <summary>
        /// Polar angle of azimutal coordinate system
        /// </summary>
        public double p
        {
            get { return sc.y; }
            set {
                sc.y = value % (2 * Math.PI);
                //RecalcCameraMovementY();
                calculateCartesianCoordinates();
            }
        }

        public double r
        {
            get { return sc.z; }
            set {                
                sc.z = value;
                if (sc.z < radiusmin) sc.z = radiusmin;
                if (sc.z > radiusmax) sc.z = radiusmax;
                calculateCartesianCoordinates();
            }
        }
        #endregion

        #region Cartesian coordinate system
        XYZ cc; //cartesian coordinates
        public double x { get { return cc.x; } }
        public double y { get { return cc.y; } }
        public double z { get { return cc.z; } }
        
        private void calculateCartesianCoordinates()
        {            
            cc.x = sc.z * Math.Sin(sc.x) * Math.Cos(sc.y);
            cc.y = sc.z * Math.Sin(sc.x) * Math.Sin(sc.y);
            cc.z = sc.z * Math.Cos(sc.x);
        }
        #endregion

        private void RecalcCameraMovementY()
        {

        }
    }
}
